package com.manager.car.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.google.gson.Gson;
import com.manager.car.po.CandidateInfo;
import com.manager.car.service.ICandidateInfoService;
import com.manager.car.util.PageModel;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class CandidateInfoAction extends ActionSupport{
  
	private static final long serialVersionUID = 1L;

    private ICandidateInfoService candidateInfoService; 
	private PageModel<CandidateInfo> pageModel;
    private CandidateInfo ci;
	private Integer id;
	private Integer limit;
	private Integer page;
    //查询所有的面试者信息
  	public void queryPageModelFrom() throws IOException {
  		
  		HttpServletResponse response = ServletActionContext.getResponse();
  		response.setContentType("application/json");
  		response.setCharacterEncoding("utf-8");
  		PrintWriter out = response.getWriter();
  		if(page==null) {
  			page = 1;
  		}
  		if(limit==null) {
  			limit=15;
  		}
  		System.out.println(1);
  		PageModel<CandidateInfo> data = candidateInfoService.queryPageModelByHql(page,limit);
  		
  		Gson gson = new Gson();
  		String json = gson.toJson(data);
  		System.out.println(json);
  		out.print(json);
  		out.flush();
  		out.close();
  	}
    public String queryAll() {
    	List<CandidateInfo> list = candidateInfoService.queryAll();
    	ActionContext.getContext().put("list", list);
		return "list";
    }
    public String queryAll_ht() {
    	List<CandidateInfo> list = candidateInfoService.queryAll();
    	ActionContext.getContext().put("list", list);
		return "list1";
    }
    public String add() {
    	candidateInfoService.add(ci);
    	ActionContext.getContext().put("msg", "1");
    	return "add";
    }
    public String queryId() {
    	CandidateInfo candidateInfo = candidateInfoService.queryId(id);
    	ActionContext.getContext().put("queryId", candidateInfo);
    	
    	return "queryId";
    }
    public void editCand() throws IOException {
    	System.out.println(111111111);
    	HttpServletResponse response = ServletActionContext.getResponse();
  		response.setContentType("application/json");
  		response.setCharacterEncoding("utf-8");
  		PrintWriter out = response.getWriter();
    	boolean bool = candidateInfoService.update(ci);
    	
  		
  		out.print(bool);
  		out.flush();
  		out.close();
    }
    public String delete() {
    	candidateInfoService.delete(id);
    	ActionContext.getContext().put("msg", "1");
    	return "delete";
    }
    
    
    
    
    
    
    
    
    
    
	public ICandidateInfoService getCandidateInfoService() {
		return candidateInfoService;
	}
	public void setCandidateInfoService(ICandidateInfoService candidateInfoService) {
		this.candidateInfoService = candidateInfoService;
	}
	public CandidateInfo getCi() {
		return ci;
	}
	public void setCi(CandidateInfo ci) {
		this.ci = ci;
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public PageModel<CandidateInfo> getPageModel() {
		return pageModel;
	}
	public void setPageModel(PageModel<CandidateInfo> pageModel) {
		this.pageModel = pageModel;
	}
	public Integer getLimit() {
		return limit;
	}
	public void setLimit(Integer limit) {
		this.limit = limit;
	}
	public Integer getPage() {
		return page;
	}
	public void setPage(Integer page) {
		this.page = page;
	}
    
    
    
    
    
    
    
    
}
